#include<bits/stdc++.h>
#define ONLINE_JUDGE
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e6 + 10, INF = 0x3f3f3f3f;

int n, q, st = 0;
int a[N];

void solve()
{
    cin >> n >> q;
    for (int i = 0;i < n;i++) a[i] = i + 1;
    while (q--) {
        int op, p, x; cin >> op;
        if (op == 1) {
            cin >> p >> x;p--;
            a[(st + p) % n] = x;
        } else if (op == 2) {
            cin >> p;p--;
            cout << a[(st + p) % n] << '\n';
        } else {
            cin >> p;
            st = (st + p) % n;
        }
    }
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}